package net.xdclass.rbac_shiro.service.impl;

import net.xdclass.rbac_shiro.dao.RoleMapper;
import net.xdclass.rbac_shiro.dao.UserMapper;
import net.xdclass.rbac_shiro.domain.Role;
import net.xdclass.rbac_shiro.domain.User;
import net.xdclass.rbac_shiro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: rbac_shiro
 * @description: User实现类
 * @author: rZ
 * @create: 2020-01-10 11:35
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findAllUserInfoByUserName(String username) {
        User user = userMapper.findByUsername(username);
        //查询用户的角色集合
        List<Role> roleList = roleMapper.findRoleListByUserId(user.getId());
        user.setRoleList(roleList);
        return user;
    }

    @Override
    public User findSimpleUserInfoById(int userId) {
        User user = userMapper.findById(userId);
        return user;
    }

    @Override
    public User findSimpleUserInfoByUserName(String username) {
        User user = userMapper.findByUsername(username);
        return user;
    }
}
